<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ReactJS 04 使用外部插件的组件</title>
    <script src="https://cdn.bootcss.com/react/16.2.0/umd/react.production.min.js"></script>
    <script src="https://cdn.bootcss.com/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
    <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>

    <link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/vs2015.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
    <script src="https://cdn.bootcss.com/remarkable/1.7.1/remarkable.min.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div id="root"></div>

<script type="text/babel">
    class MarkdownEditor extends React.Component {
        constructor(props) {
            super(props);
            this.handleChange = this.handleChange.bind(this);
            this.state = { value: 'Type some *markdown* here!' };
        }

        handleChange(e) {
            this.setState({ value: e.target.value });
        }

        getRawMarkup() {
            const md = new Remarkable();
            return { __html: md.render(this.state.value) };
        }

        render() {
            return (
                <div className="MarkdownEditor">
                    <h3>Input</h3>
                    <textarea
                        onChange={this.handleChange}
                        defaultValue={this.state.value}
                    />
                    <h3>Output</h3>
                    <div
                        className="content"
                        dangerouslySetInnerHTML={this.getRawMarkup()}
                    />
                </div>
            );
        }
    }

    ReactDOM.render(
        <MarkdownEditor  />,
        document.getElementById('root')
    );
</script>

</body>
</html>